﻿#region Using

using System.Xml.Serialization;

using Common.Enums;

using GameCommon.Components;

using Menu.Common;
using Menu.Service;
using Menu.XmlEntities;

using GlobalServices = GameCommon.Services.Service;

#endregion

namespace Menu
{
    public static class MenuLoader
    {
        public static ComponentCollection Get(ScreenEnum screen)
        {
            XmlValidationService.Validate(screen);

            var path = GlobalServices.PathService.GetMenuXml(screen);

            XmlScreen xmlScreen;
            using (var stream = GlobalServices.FileService.GetEmbeddedRessource(path))
            {
                var xmlSerializer = new XmlSerializer(typeof(XmlScreen));
                xmlScreen = xmlSerializer.Deserialize(stream) as XmlScreen;
            }

            return ComponentLoader.GetComponentCollection(xmlScreen);
        }
    }
}